<template>
  <div>
    <el-form :model="form" inline>
      <el-form-item label="选择仓库：">
        <el-select v-model="form.warehouseId" style="width: 120px">
          <el-option :label="item.name" :value="item.id" v-for="item in store.NewHouseList" :key="item.id" />
        </el-select>
      </el-form-item>

      <el-form-item label="订单平台：">
        <el-select v-model="form.platform" style="width: 120px">
          <el-option :label="item" :value="item" v-for="(item, index) in shujuSelectList" :key="index" />
        </el-select>
      </el-form-item>
      <el-form-item label="订单号：">
        <el-input v-model="form.orderOid" style="width: 170px" />
      </el-form-item>
      <el-form-item label="出库运单号：">
        <el-input v-model="form.orderInvoiceNo" style="width: 170px" />
      </el-form-item>
      <el-form-item label="没有出库运单号的原因：">
        <el-select v-model="form.failMsg" style="width: 170px">
          <el-option :label="item" :value="item" v-for="(item, index) in outSaleOrdergetFailMsgListTable"
            :key="index" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">搜索</el-button>
      </el-form-item>
    </el-form>
    <div class="table">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="仓库" width="120">
          <template #default="scope">{{ scope.row.warehouseName }}</template>
        </el-table-column>
        <el-table-column label="货主" width="120">
          <template #default="scope">{{ scope.row.company }}</template>
        </el-table-column>
        <el-table-column label="订单号" width="220">
          <template #default="scope">{{ scope.row.orderOid }}</template>
        </el-table-column>
        <el-table-column label="拣货人" width="120">
          <template #default="scope">{{ scope.row.pickPerson }}</template>
        </el-table-column>
        <el-table-column label="拣货单单号" width="220">
          <template #default="scope">{{ scope.row.prePickOrderNum }}</template>
        </el-table-column>
        <el-table-column label="打包人" width="120">
          <template #default="scope">{{ scope.row.packPerson }}</template>
        </el-table-column>
        <el-table-column label="打包时间" width="150">
          <template #default="scope">{{ scope.row.packTime }}</template>
        </el-table-column>
        <el-table-column label="出库单号" width="150">
          <template #default="scope">{{ scope.row.orderInvoiceNo }}</template>
        </el-table-column>
        <el-table-column label="出库重量" width="80">
          <template #default="scope">{{ scope.row.outWeight }}/kg</template>
        </el-table-column>
        <el-table-column label="拣货库位" width="150">
          <template #default="scope">{{ scope.row.warehouseLocationName }}</template>
        </el-table-column>
        <el-table-column label="失败原因" width="150">
          <template #default="scope">{{ scope.row.failMsg }}</template>
        </el-table-column>
        <el-table-column label="操作">
          <!-- <template #default="scope">
            <el-button link type="primary" size="small" @click.prevent="outboundBtn(scope.row)">
              出库
            </el-button>
          </template> -->
        </el-table-column>
      </el-table>
    </div>
  </div>
  <div class="page">
    <el-pagination v-model:current-page="currentPage4" v-model:page-size="pageSize4" :page-sizes="[10, 50, 100]"
      layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
      @current-change="handleCurrentChange" />
  </div>
</template>

<script setup>
import { ref, onBeforeMount } from 'vue'
import { outSaleOrdergetOutFailOrderList, afterDestructionOrdergetDataFromList, outSaleOrdergetFailMsgList } from '@/api/index'
// import { ElMessage } from 'element-plus'
import { useAlertsStore } from '@/store/index'
const store = useAlertsStore()
const pageForm = ref({
  pageSize: 10,
  pageNum: 1
})
onBeforeMount(() => {
  shujuSelect()
  outSaleOrdergetFailMsgListBtn()
  getList()
})
const form = ref({
  warehouseId: -1,
  platform: '全部',
  orderOid: '',
  orderInvoiceNo: '',
  failMsg: '全部'
})
// table多选

const getList = () => {
  outSaleOrdergetOutFailOrderList(Object.assign({}, pageForm.value, form.value)).then(res => {
    const { data: { data } } = res
    total.value = data.total
    tableData.value = data.list
  })
}
// 分页
const tableData = ref([])
const currentPage4 = ref(1)
const pageSize4 = ref(10)
const total = ref(0)
const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
  pageForm.value.pageSize = val
  getList()
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
  pageForm.value.pageNum = val
  getList()
}
// 下拉数据
const shujuSelectList = ref([])
const shujuSelect = () => {
  afterDestructionOrdergetDataFromList().then(res => {
    console.log('res')
    console.log(res)
    const { data: { data } } = res
    shujuSelectList.value = data
  })
}
// 下拉数据
const outSaleOrdergetFailMsgListTable = ref([])
const outSaleOrdergetFailMsgListBtn = () => {
  outSaleOrdergetFailMsgList().then(res => {
    console.log('res')
    console.log(res)
    const { data: { data } } = res
    outSaleOrdergetFailMsgListTable.value = data
  })
}
const onSubmit = () => {
  getList()
}

// // 出库
// const outboundBtn = (row) => {
//   outSaleOrderout({ id: row.id }).then(res => {
//     ElMessage.success('操作成功')
//     getList()
//   })
// }
</script>

<style lang='less' scoped></style>
